home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 400_01 / socketpp-1.5 / sockinet.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-06  |  3.7 KB  |  122 lines

  1. // sockinet.h -*- C++ -*- socket library
  2. // Copyright (C) 1992,1993 Gnanasekaran Swaminathan <gs4t@virginia.edu>
  3. // 
  4. // Permission is granted to use at your own risk and distribute this software
  5. // in source and binary forms provided the above copyright
  6. // notice and this paragraph are preserved on all copies.
  7. // This software is provided "as is" with no express or implied warranty.
  8. //
  9. // Version: 31Jan93 1.3
  10.  
  11. #ifndef _SOCKINET_H
  12. #define    _SOCKINET_H
  13.  
  14. #include <sockstream.h>
  15. #include <netinet/in.h>
  16.  
  17. class sockinetaddr: public sockAddr, public sockaddr_in {
  18. protected:
  19.     void        setport (const char* sn, const char* pn="tcp");
  20.     void        setaddr (const char* hn);
  21. public:
  22.                 sockinetaddr ();
  23.                 sockinetaddr (unsigned long addr, int port_no=0);
  24.                 sockinetaddr (const char* host_name, int port_no=0);
  25.                 sockinetaddr (unsigned long addr,
  26.                       const char* service_name,
  27.                       const char* protocol_name="tcp");
  28.                 sockinetaddr (const char* host_name,
  29.                        const char* service_name,
  30.                       const char* protocol_name="tcp");
  31.                 operator void* () const { return (sockaddr_in*)this; }
  32.  
  33.     int         size() const { return sizeof (sockaddr_in); }
  34.     int         family() const { return sin_family; }
  35.     
  36.     int            getport() const { return ntohs (sin_port); }
  37.     const char*     gethostname() const;
  38. };
  39.  
  40. class sockinetbuf: public sockbuf {
  41. protected:
  42.     sockinetbuf&    operator=(sockbuf& si); // needs to be fixed
  43. public:
  44.     enum domain { af_inet = 2 };
  45.     
  46.                 sockinetbuf (const sockbuf& si): sockbuf(si) {}
  47.                 sockinetbuf (sockbuf::type ty, int proto=0);
  48.     
  49.     sockbuf*        open (sockbuf::type, int proto=0);
  50.     
  51.     sockinetaddr    localaddr() const;
  52.     int            localport() const;
  53.     const char*        localhost() const;
  54.     
  55.     sockinetaddr    peeraddr() const;
  56.     int            peerport() const;
  57.     const char*        peerhost() const;
  58.  
  59.     virtual void    bind (sockAddr& sa);
  60.     void        bind ();
  61.     void        bind (unsigned long addr, int port_no=0);
  62.     void        bind (const char* host_name, int port_no=0);
  63.     void        bind (unsigned long addr,
  64.                   const char* service_name,
  65.                   const char* protocol_name="tcp");
  66.     void        bind (const char* host_name,
  67.                   const char* service_name,
  68.                   const char* protocol_name="tcp");
  69.  
  70.     virtual void    connect (sockAddr& sa);
  71.     void        connect (unsigned long addr, int port_no=0);
  72.     void        connect (const char* host_name, int port_no=0);
  73.     void        connect (unsigned long addr,
  74.                  const char* service_name,
  75.                  const char* protocol_name="tcp");
  76.     void        connect (const char* host_name,
  77.                  const char* service_name,
  78.                  const char* protocol_name="tcp");
  79.  
  80. };
  81.  
  82. class isockinet: public isockstream
  83. {
  84. public:
  85.                 isockinet (const sockbuf& sb);
  86.                 isockinet (sockbuf::type ty=sockbuf::sock_stream,
  87.                           int proto=0);
  88.                 isockinet (sockinetbuf* sb, ostream* tied=0)
  89.                 : ios (sb, tied) { setf (ios::dont_close); }
  90.  
  91.     sockinetbuf*    rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
  92.     sockinetbuf*    operator -> () { return rdbuf (); }
  93. };
  94.  
  95. class osockinet: public osockstream
  96. {
  97. public:
  98.                 osockinet (const sockbuf& sb);
  99.                 osockinet (sockbuf::type ty=sockbuf::sock_stream,
  100.                    int proto=0);
  101.                 osockinet (sockinetbuf* sb, ostream* tied=0)
  102.                 : ios (sb, tied) { setf (ios::dont_close); }
  103.  
  104.     sockinetbuf*    rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
  105.     sockinetbuf*    operator -> () { return rdbuf (); }
  106. };
  107.  
  108. class iosockinet: public iosockstream
  109. {
  110. public:
  111.                 iosockinet (const sockbuf& sb);
  112.                 iosockinet (sockbuf::type ty=sockbuf::sock_stream,
  113.                     int proto=0);
  114.                 iosockinet (sockinetbuf* sb, ostream* tied=0)
  115.                 : ios (sb, tied) { setf (ios::dont_close); }
  116.  
  117.     sockinetbuf*    rdbuf () { return (sockinetbuf*)ios::rdbuf (); }
  118.     sockinetbuf*    operator -> () { return rdbuf (); }
  119. };
  120.  
  121. #endif    _SOCKINET_H
  122.